//
//  File.swift
//  
//
//  Created by Jiang Chencheng on 2024/9/4.
//

import Foundation


extension String {
    
    static func random(with length: Int, from characters: String? = nil) -> String {
        
        let characters = characters ?? "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
       
        var randomString = ""
        for _ in 0..<length {
            if let char = characters.randomElement() {
                randomString.append(char)
            }
        }
        
        return randomString
    }
    
}
